﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Linq;
using System.Net.Mime;
using System.Web;
using System.Web.Mvc;
using Newtonsoft.Json;

namespace NC.Web.Models
{
    public class ApiJson:JsonResult
    {
        public ApiJson(object obj,ResultStatus status = ResultStatus.BadRequest)
        {
            var result = new ApiJsonResult(obj, status);
            ContentType = "application/json";
            JsonRequestBehavior = JsonRequestBehavior.AllowGet;
            string resultStr = JsonConvert.SerializeObject(result, Newtonsoft.Json.Formatting.Indented,
                new DateTimeConverter());
            Data = resultStr;
        }

        public ApiJson(ResultStatus status = ResultStatus.Ok)
        {
            var result = new ApiJsonResult(status);
            ContentType = "application/json";
            JsonRequestBehavior = JsonRequestBehavior.AllowGet;
            string resultStr = JsonConvert.SerializeObject(result, Newtonsoft.Json.Formatting.Indented,
                new DateTimeConverter());
            Data = resultStr;
        }

    }
}